#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""  
@Project : PythonProject4
@File : ssh_val.py
@Author : 徐大大
@Time : 2025/7/6 14:43  
@脚本说明 : 

"""

import threading

import paramiko



def scan_ssh(host, port, user, password):
    try:        # 1. 构建 tcp 传输通道 生成 transport 连接语句柄
        transport = paramiko.Transport((host, port))
        transport.connect(username=user, password=password)
        transport.banner_timeout = 60
        ssh_client = paramiko.SSHClient()
        print(f"[+] ssh {host}:{port} 存在弱口令, {user}:{password}")
        with open(file="./ssh_result.txt", mode="a+", encoding="utf-8") as f:
            f.write(f"[+] ssh {host}:{port} 存在弱口令, {user}:{password}\n")
    except:
        pass


def val_ssh(host, port, user, file):
    try:
        thread_list = []
        with open(f"{file}", mode='r', encoding="utf-8") as p:
            for passwd in p:
                t = threading.Thread(target=scan_ssh, args=(host, port, user.strip(), passwd.strip()))
                t.start()
                thread_list.append(t)
        for t in thread_list:
            t.join()
    except:
        print("[-] 爆破失败")
